package com.evan.uyclub.HomeFragment;


import android.animation.ObjectAnimator;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;

import com.evan.uyclub.About.AboutActivity;
import com.evan.uyclub.Other.UserData;
import com.evan.uyclub.Other.Utlis;
import com.evan.uyclub.R;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.sdsmdg.tastytoast.TastyToast;
import com.squareup.picasso.Picasso;
import com.wx.ovalimageview.RoundImageView;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

/**
 * @noinspection ALL
 */
public class MyFragment extends LazyFragment {
    ObjectAnimator objectAnimator;
    private SharedPreferences data;
    private View view;
    private TextView users, names, ycgg;
    private RoundImageView icon;
    private LinearLayout ckgg, fen_app, about;
    private WebView icon_web;

    private TwinklingRefreshLayout my_s;

    /*@Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_my, container, false);
        return view;
    }*/

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_my;
    }

    @Override
    protected void initView(View views) {
        view = views;
    }

    @Override
    protected void initData() {
        initUI();
    }

    private void initUI() {
        about = view.findViewById(R.id.add_article);
        about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(requireActivity(), AboutActivity.class);
                startActivity(intent);
                requireActivity().overridePendingTransition(R.anim.activity_visible, R.anim.activity_gone);
            }
        });
        //获取查看公告的线性布局
        ckgg = view.findViewById(R.id.my_ckgg);
        ckgg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BottomSheetDialog dialog = new BottomSheetDialog(getActivity());
                View dialog1 = getLayoutInflater().inflate(R.layout.gg_my, null);
                dialog.setContentView(dialog1);
                dialog.setCancelable(true);
                dialog.setCanceledOnTouchOutside(true);
                dialog.show();
                dialog.getWindow().findViewById(R.id.design_bottom_sheet).setBackgroundResource(R.color.bantouming);
                //获取弹窗界面的id方法
                ycgg = dialog1.findViewById(R.id.my_gg);
                CardView qxgg = (CardView) dialog1.findViewById(R.id.qxgg);
                qxgg.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();
                    }
                });
                initGG();
            }
        });
        //设置对应xml界面的字体
        TextView up_title = view.findViewById(R.id.up);
        TextView cloud_title = view.findViewById(R.id.cloud);
        users = view.findViewById(R.id.user);
        names = view.findViewById(R.id.name);
        icon = view.findViewById(R.id.icon);
        Picasso.with(getActivity()).load(R.mipmap.a69).noPlaceholder().into(icon);
        icon_web = view.findViewById(R.id.webview);
        //动起来  ---不能写，因为一打开首页这些动画就开始执行
        up_title.setTypeface(Typeface.createFromAsset(requireActivity().getAssets(), "english.ttf"));
        cloud_title.setTypeface(Typeface.createFromAsset(requireActivity().getAssets(), "english.ttf"));
        my_s = view.findViewById(R.id.app_s);
        my_s.setPureScrollModeOn();
        ImageView my_data = (ImageView) view.findViewById(R.id.my_data);
        my_data.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                /*String user = users.getText().toString().trim();
                Intent intent = new Intent();
                intent.putExtra("user", user);
                intent.setClass(getActivity(), MyData.class);
                startActivity(intent);
                requireActivity().overridePendingTransition(R.anim.activity_visible, R.anim.activity_gone);*/
                TastyToast.makeText(getContext(), "已关闭用户实例.👋", TastyToast.LENGTH_LONG, TastyToast.CONFUSING);
            }
        });
        LinearLayout click_user_edit = view.findViewById(R.id.my_data1);
        click_user_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                /*String user = users.getText().toString().trim();
                Intent intent = new Intent();
                intent.putExtra("user", user);
                intent.setClass(getActivity(), MyData.class);
                startActivity(intent);
                requireActivity().overridePendingTransition(R.anim.activity_visible, R.anim.activity_gone);*/
                TastyToast.makeText(getContext(), "已关闭用户实例.👋", TastyToast.LENGTH_LONG, TastyToast.CONFUSING);
            }
        });
        LinearLayout uyzhgi = view.findViewById(R.id.uyzhi);
        uyzhgi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TastyToast.makeText(getContext(), "已关闭用户实例.👋", TastyToast.LENGTH_LONG, TastyToast.CONFUSING);
            }
        });
        fen_app = view.findViewById(R.id.fen_app);
        fen_app.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, "UyClub是个很奇特的工具箱，内涵 100+ 使用工具箱.📦包括精选壁纸,个性头像,童年游戏...🥹!UyClub官方下载地址:https://jfkj.xyz");
                sendIntent.putExtra(Intent.EXTRA_TITLE, "UyClub多功能实用工具箱.🛠️");
                // 设置分享的类型
                sendIntent.setType("text/plain");
                Intent shareIntent = Intent.createChooser(sendIntent, null);
                startActivity(shareIntent);
            }
        });
        //调用获取
        users.setText(UserData.getUser());
        names.setText(UserData.getName());

    }

    private void initGG() {
        if (!Utlis.isVPNConnected(getContext())) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    EasyHttp.get("https://uyclouds.com/uyapi/file_text.php")
                            .params("keeper", "3487297072")
                            .params("api", "488588")
                            .params("title", "appgg")
                            .execute(new SimpleCallBack<String>() {
                                @Override
                                public void onError(ApiException e) {
                                    e.printStackTrace();
                                }

                                @Override
                                public void onSuccess(String data) {
                                    Log.e("TAG", data);
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            ycgg.setText(Html.fromHtml(data));
                                        }
                                    });
                                }
                            });
                }
            }).start();
        }
    }

    /*public void test() {
        //获取个人信息
        data = getActivity().getSharedPreferences("data", Context.MODE_PRIVATE);
        String user = data.getString("user", "");
        if (!Utlis.isVPNConnected(getContext())) {
            new Thread(new Runnable() {
                private int imageAlpha;

                @Override
                public void run() {
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            users.setText("出言有尺，做事有余。");
                            names.setText("匿名用户");
                            try {
                                Picasso.with(getActivity()).load(R.mipmap.a69).noPlaceholder().into(icon);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });

                }

            }).start();
        }

    }*/
}